<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AJAX Request Example</title>
</head>
<body>

<div id="result"></div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        function sendAjaxRequest() {
            var xhr = new XMLHttpRequest();
            var url = 'http://127.0.0.1:8888/select_user'; // 请确保此URL与您的后端服务匹配
            xhr.open('POST', url, true);
            xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');

            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    var response = JSON.parse(xhr.responseText);
                    document.getElementById('result').innerHTML = '查询结果：' + JSON.stringify(response.userinfo);
                }
            };

            const data = {
                "user": "",
                "gender": "",
                "age": "",
                "classId": "",
                "stuId": "",
                "professional": "",
                "nickname": "无条件"
            };
            console.log(data);

            xhr.send(JSON.stringify(data));
        }

        // 调用函数发送请求
        sendAjaxRequest();
    });
</script>

</body>
</html>
